package com.example.demo.chat.myhandler;

import com.alibaba.fastjson.JSON;
import com.example.demo.chat.Command;
import com.example.demo.chat.NettyAsyncServer;
import com.example.demo.chat.Result;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

public class ConnectionHandler {
    public static void  execute(Command command, ChannelHandlerContext ctx){
        if (NettyAsyncServer.player.containsKey(command.getName())){
            ctx.channel().writeAndFlush(Result.fail("已经登录过了"));
        }
        NettyAsyncServer.player.put(command.getName(),ctx.channel());
        ctx.channel().writeAndFlush(Result.sucess("连接成功"));
        ctx.channel().writeAndFlush(Result.sucess(JSON.toJSONString(NettyAsyncServer.player.keySet())));

    };
}
